package com.blyat.xsoft.kernel.component.mq.rocketmq;

import org.apache.rocketmq.spring.autoconfigure.RocketMQProperties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @Auther: syh
 * @Date: 2020/8/7
 * @Description:
 */
public abstract class RocketMQContextLoader implements ApplicationContextAware, SmartInitializingSingleton {
    private ConfigurableApplicationContext applicationContext;
    private RocketMQProperties properties;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = (ConfigurableApplicationContext) applicationContext;
    }

    @Override
    public void afterSingletonsInstantiated() {
        this.properties = applicationContext.getBean(RocketMQProperties.class);
        doAfterSingletonsInstantiated();
    }

    public ConfigurableApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public RocketMQProperties getProperties() {
        return properties;
    }

    protected abstract void doAfterSingletonsInstantiated();
}
